# -*- coding: utf-8 -*-
# @Author    : Tian Wencheng
# @CreateTime: 2021/1/15 17:20
# @FileName  : system_management.py
# @IDE       : PyCharm
# @Git       : https://gitee.com/dianetian/projects


from common.request import HTTPRequest
from interface.base import BaseModule


class SystemManagementModule(BaseModule):
    def __init__(self):
        self.request_url = ""
        self.request_method = ""
        self.request_headers = {"Content-Type": "application/json"}
        self.request_params = None
        self.cookies = super().cookies
        self.web_url = super().web_url

    def update_user_password(self, **kwargs):
        id = kwargs.get("id")
        current_password = kwargs.get("currentPass")
        new_password = kwargs.get("newPass")

        self.request_url = "/api/updatePass"
        url = self.web_url + self.request_url
        self.request_method = "POST"
        self.request_params = {"id": id, "currentPass": current_password, "newPass": new_password}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def delete_user(self, **kwargs):
        ids = kwargs.get("ids")

        self.request_url = "/api/user"
        url = self.web_url + self.request_url
        self.request_method = "DELETE"
        self.request_params = {"ids": ids}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def delete_role(self, **kwargs):
        ids = kwargs.get("ids")

        self.request_url = "/api/role"
        url = self.web_url + self.request_url
        self.request_method = "DELETE"
        self.request_params = {"ids": ids}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def add_user(self, **kwargs):
        job_number = kwargs.get("jobNumber")
        account = kwargs.get("account")
        real_name = kwargs.get("realName")
        email = kwargs.get("email")
        phone = kwargs.get("phone")
        role_id = kwargs.get("roleId")

        self.request_url = "/api/user"
        url = self.web_url + self.request_url
        self.request_method = "POST"
        self.request_params = {"jobNumber": job_number, "account": account, "realName": real_name, "email": email,
                               "phone": phone, "roleId": role_id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def update_user(self, **kwargs):
        id = kwargs.get("id")
        job_number = kwargs.get("jobNumber")
        account = kwargs.get("account")
        real_name = kwargs.get("realName")
        email = kwargs.get("email")
        phone = kwargs.get("phone")
        role_id = kwargs.get("roleId")

        self.request_url = "/api/user"
        url = self.web_url + self.request_url
        self.request_method = "POST"
        self.request_params = {"jobNumber": job_number, "account": account, "realName": real_name, "email": email,
                               "phone": phone, "roleId": role_id, "id": id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def add_role(self, **kwargs):
        name = kwargs.get("name")
        menu_ids = kwargs.get("menuIds")
        camera_ids = kwargs.get("cameraIds")

        self.request_url = "/api/role"
        url = self.web_url + self.request_url
        self.request_method = "POST"
        self.request_params = {"name": name, "menuIds": menu_ids, "cameraIds": camera_ids}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def update_role(self, **kwargs):
        id = kwargs.get("id")
        name = kwargs.get("name")
        menu_ids = kwargs.get("menuIds")
        camera_ids = kwargs.get("cameraIds")

        self.request_url = "/api/role"
        url = self.web_url + self.request_url
        self.request_method = "POST"
        self.request_params = {"id": id, "name": name, "menuIds": menu_ids, "cameraIds": camera_ids}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_user(self, **kwargs):
        real_name = kwargs.get("realName")
        account = kwargs.get("account")
        job_number = kwargs.get("jobNumber")
        current_page = kwargs.get("currentPage")
        page_size = kwargs.get("pageSize")

        self.request_url = "/api/user"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"realName": real_name, "account": account, "jobNumber": job_number,
                               "currentPage": current_page, "pageSize": page_size}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_role(self, **kwargs):
        role_name = kwargs.get("roleName")

        self.request_url = "/api/role"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"roleName": role_name}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_personal_info(self):
        self.request_url = "/api/personal"
        url = self.web_url + self.request_url
        self.request_method = "GET"

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_available_menus(self):
        self.request_url = "/api/manager/menulist"
        url = self.web_url + self.request_url
        self.request_method = "GET"

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def reset_user_password(self, **kwargs):
        id = kwargs.get("id")

        self.request_url = "/api/user/resetPass"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"id": id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response
